﻿using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using HHControls.CreditEducation;
using IGM.WcfService;

namespace IGM.Presentation.Main
{
    public partial class MainView : HHMainForm
    {
        public static MainView Instance;
        public DomainService IgmService { get; set; }

        #region Constructor

        public MainView()
        {
            InitializeComponent();

            IgmService = new DomainService();

            Instance = this;
           
            RefreshWhenAddStudyPlan();
        }

        private void TmrTimeTick(object sender, EventArgs e)
        {
            lblTimes.Text = @"Bây giờ là: " + DateTime.Now.ToLocalTime();
        }
        #endregion

        #region Public Methods

        public void AddUserControlToPanel(Control userControl)
        {
            pnlMain.Controls.Clear();
            pnlMain.Controls.Add(userControl);
        }

        public void ShowTextCurrentModule(string moduleText)
        {
            lblCurrentModule.Text = moduleText;
        }

        public void ApplyStatus(string status)
        {
            lblTimes.Text = status;
        }

        public void ApplyChangeUserInformation(string name, Bitmap image)
        {
            lblUserName.Text = name;
            ptbAvatar.Image = image;
        }

        public void RefreshWhenAddStudyPlan()
        {
            Navigation.Initialize();                  

            var info = new Login();
            info.Show();
            Navigation.Show(pnlLeft.Controls);
            Navigation.ExpandGroup(Navigation.NavGroups.First(g => g.Name == "expMain"));

            if (pnlMain.Controls.Count < 1)
            {
                Navigation.ShowControlOnPanel(Navigation.NavItems.First(n => n.Name == FirstOpen));
            }
            else
            {
                Navigation.NavItems.First(n => n.Name == FirstOpen).Instance.IsClicked = true;
            }
        }

        public void GoToStudyPlanScreen(string name)
        {
            Navigation.ExpandGroup(Navigation.NavGroups.First(g => g.Name == "expMain"));

            Navigation.ShowControlOnPanel(Navigation.NavItems.First(n => n.Name == name));
        }

        #endregion              
    }
}
